package lesson.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lesson.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description:
 * @Author: Wanzhen
 * @Date: 2022/6/13-10:19
 */
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select mid from role_menu where rid = #{roleId}")
    List<Integer> queryAllPermissionByRid(Integer roleId);

    //分配菜单栏之前删除所有的rid数据
    @Delete("delete from role_menu where rid = #{rid}")
    void deleteRoleByRid(Integer rid);

    //保存分配角色与菜单的关系
    @Insert("insert into role_menu(rid,mid) values(#{rid},#{mid})")
    void saveRoleMenu(Integer rid, Integer mid);

    //根据用户id查询其所有的角色
    @Select("select rid from user_role where uid = #{id}")
    List<Integer> queryUserRoleById(Integer id);

    //先删除之前的用户与角色关系
    @Delete("delete from user_role where uid = #{uid}")
    void deleteRoleUserByUid(Integer uid);

    //保存分配的用户与角色的关系
    @Insert("insert into user_role(uid,rid) values(#{uid},#{rid})")
    void saveUserRole(Integer uid, Integer rid);

}
